package chazhao;

//题目描述：在一个数组中找出最长的递增子序列
public class 最长连续递增子序列 {
    public static void main(String[] args) {
        int[] array = new int[]{1, 3, 5, 4, 7,10,11};
        int lengthOfLCIS = findLengthOfLCIS(array);
        System.out.println("最长子序列长度:"+lengthOfLCIS);
    }
    static int findLengthOfLCIS(int[] nums) {
        int low = 0;//慢指针
        int len = 1;
        int begin = 0;//记录最长子序列的起始下标
        int end = 1;//记录最长子序列的结束下标
        int maxLen = 0;
        if (nums.length == 1)
            return 1;
        for (int i = 1; i < nums.length; i++) {
            if (len > maxLen) {
                maxLen = len;
                begin = i;
                end = i;
            }
            if (nums[i] > nums[i - 1]) {
                len++;
            } else {
                low = i;
                len = 1;
            }
        }
        if (len > maxLen) {
            maxLen = len;
        }
        System.out.print("最长子序列：");
        for (int i = begin; i <= end; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
        return maxLen;
    }
}
